package ACWing.Dynamicprogramming.Backpack;
//4. 多重背包问题 I
//5. 多重背包问题 II

import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/11/12 16:54
 */
public class MultipleBackpacks {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int V= sc.nextInt();
        int[]v=new int[25000];//当前物体的体积计算方法N*logS【i】
        int[]w=new int[25000];//当前物体的价值
        int n=1;//移动下标
        for (int i = 0; i < N; i++) {
            int a=sc.nextInt();
            int b=sc.nextInt();
            int s=sc.nextInt();
            int k=1;
            while (k<=s){ //分堆
               v[n]=a*k;
               w[n]=b*k;
               n++;
               s=s-k;
               k=k*2;
            }if(s>0){
                v[n]=a*s;
                w[n]=b*s;
                n++;
            }

        }
        int[]dp=new int[V+1];
        for (int i = 1; i <n; i++) {
            for (int j = V; j >=v[i]; j--) {
                dp[j]=Math.max(dp[j],dp[j-v[i]]+w[i]);
            }

        }
        System.out.println(dp[V]);
    }

}
